package com.xfd.learn.config;

import com.xfd.learn.aspect.RequestLoggerAspect;
import com.xfd.learn.constant.LoggerConstant;
import com.xfd.learn.prop.LoggerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * 1.不支持热插拔，引入依赖即说明你需要
 * 2.目前只支持web项目
 * 3.可对所有的请求，进行日志输出打印
 * 4.支持异步线程的跟踪
 * @since 2024-10-23
 * @author xfd
 */
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties({LoggerProperties.class})
public class LoggerAutoConfiguration {

    /**
     * 默认加载日志切面增强
     */
    @Bean
    @ConditionalOnProperty(value = LoggerConstant.LOGGER_PROPERTIES_PREFIX + ".enable", havingValue = "true", matchIfMissing = true)
    public RequestLoggerAspect requestLoggerAspect() {
        return new RequestLoggerAspect();
    }
}
